﻿define(
    [
        'durandal/app',
        'services/logger'
    ],
    function (app, logger) {
        var orgList = [
            { Id: 1, Name: 'Org 1' },
            { Id: 2, Name: 'Org 2' },
            { Id: 3, Name: 'Org 3' }
        ],
        activeOrganisationDetail = ko.observable(false);
        ///
        ///  CONSTRUCTOR
        ///
        var organisations = function () {
            this.displayName = 'Organisations';
            this.description = 'List of Organisations';
            this.organisationList = ko.observableArray(orgList);
            this.activeOrganisationDetail = activeOrganisationDetail;
        };

        ///
        ///  PROTOTYPES
        ///
        organisations.prototype = {
            viewAttached: function (view) {
                //you can get the view after it's bound and connected to it's parent dom node if you want
                //app.showMessage('Organisations screen is attached...');
                logger.log('Organisations screen is attached...', null, null, true);
            },
            selectOrg: function (item) {
                // item.viewUrl = 'views/organisationdetail';
                // app.showModal(item);
                app.trigger('organisation:select', item);
                activeOrganisationDetail(true);
                logger.log('Selected (Id:' + item.Id + '|Name:' + item.Name + ')', null, null, true);
            }
        };

        return organisations;
    });